<%@ page import="java.sql.Connection" %>
<%@ page import="java.sql.Statement" %>
<%@ page import="java.sql.ResultSet" %>
<%@ page import="java.sql.DriverManager" %>
<%@ page import="java.util.List" %>
<%@ page import="java.util.ArrayList" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
  Created by IntelliJ IDEA.
  User: JAVA
  Date: 2018/6/3
  Time: 12:09
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>用户列表</title>
</head>
<body>
<style type="text/css">
    table{
        border-collapse: collapse;
    }
    td{
        border: 1px solid #000;
        padding: 10px;
    }
</style>
<p><a href="userAdd.jsp">添加用户</a></p>
<table>
    <tr>
        <td>考试内容</td>
        <td>准备时间</td>
        <td>提醒内容</td>
        <td>考试时间</td>
        <td>提醒内容</td>
        <td>电话号码</td>
        <td>删除</td>
        <td>更新</td>
    </tr>

    <%
        //脚本
        //3+1 从数据库查数据
        Connection connection=null;
        Statement statement=null;
        ResultSet resultSet=null;
        String sql="select * from sctu_on_time";
        //加动驱动程序
        Class.forName("com.mysql.jdbc.Driver");
        connection= DriverManager.getConnection(
                "jdbc:mysql://localhost:3306/on_time?serverTimezone=UTC",
                "root",
                "123456"//大家的密码是123456
        );
        statement=connection.createStatement();
        resultSet=statement.executeQuery(sql);

        class User{
            int id;
            String title;
            String time1;
            String content1;
            String time2;
            String  content2;
            String tel;


        }
        List<User> userList=new ArrayList<User>();
        while (resultSet.next()){
            int id=resultSet.getInt(1);
            String title= resultSet.getString(2);//取数据库的第一列
            String time1=resultSet.getString(3);//取数据库的第二列
            String content1=resultSet.getString(4);//娶数据库的第三列
            String time2=resultSet.getString(5);//娶数据库的第4列
            String content2=resultSet.getString(6);//娶数据库的第5列
            String tel =resultSet.getString(7);//娶数据库的第6列
            User user=new User();
            user.id=id;
            user.title=title;
            user.time1=time1;
            user.content1=content1;
            user.time2=time2;
            user.content2=content2;
            user.tel=tel;
            userList.add(user);
        }
        resultSet.close();
        statement.close();
        connection.close();
        for (User u:userList){
            out.write("<tr>" +
                    " <td>"+u.title+"</td>" +
                    " <td>"+u.time1+"</td>" +
                    " <td>"+u.content1+"</td>" +
                    " <td>"+u.time2+"</td>" +
                    " <td>"+u.content2+"</td>" +
                    " <td>"+u.tel+"</td>" +
                    "<td><a href='deleteUserHandler.jsp?id="+u.id+"'>删除</a></td>"+
                    "<td><a href='userUpdate.jsp?id="+u.id+"&time1="+u.time1+ "&time2="+u.time2+"&tel="+u.tel+"'>更新</a></td>"+
                    "</tr>"
            );
        }
    %>
</table>
</body>
</html>